import Vue from 'vue'
import VueRouter from 'vue-router'
 

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('../views/Main.vue'),
    children:[
      {
        path: 'home',
        name: 'home',
        component: () => import('../views/Home/index.vue'),
        children:[
          {
            path: 'shoplist',
            name: 'shoplist',
            component: () => import('../views/Home/Shoplist.vue')
          },
          {
            path: 'shop',
            name: 'shop',
            component: () => import('../views/Home/Shop.vue')
          },
        ]
      },
      {
        path: 'dingdan',
        name: 'dingdan',
        component: () => import('../views/Dingdan/index.vue'),
        children:[
          {
            path: 'jiaoyi',
            name: 'jiaoyi',
            component: () => import('../views/Dingdan/Jiaoyi.vue')
          },
          {
            path: 'htjy',
            name: 'htjy',
            component: () => import('../views/Dingdan/Htjy.vue')
          },
        ]
      },
    ],
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 全局守卫
router.beforeEach((to,from,next)=>{
  if(localStorage.getItem("token")){
    next()
  }else{
    if(to.path == '/'){
      next()
    }else{
      next("/")
    }
  }
})

export default router
